package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.constant.TencreatIdAndName;
import com.tencreat.common.constant.TencreatMapData;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.enums.mall.JumpTypeEnum;
import com.tencreat.domain.mall.MallLunbo;
import com.tencreat.domain.mall.MallStorage;
import com.tencreat.domain.mall.vo.AdminLunboVO;
import com.tencreat.domain.mall.dto.AdminLunboAddEditDTO;
import com.tencreat.service.mall.IMallLunboService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author tencreat
 * @date 2021-09-15
 */
@Api(tags="【请填写功能名称】api")
@RestController
@RequestMapping("/mall/lunbo")
public class MallLunboController extends BaseController {
    @Autowired
    private IMallLunboService mallLunboService;

    /**
     * 列表数据
     *
     * @author linjinzhan
     * @date 2018年11月14日
     * @return
     */
    @ResponseBody
    @PostMapping("list_data")
    @PreAuthorize("@ss.hasPermi('mall:lunbo:list')")
    public HttpResult<List<MallLunbo>> listData(@RequestBody MallLunbo mallLunbo) {
        QueryWrapper<MallLunbo> wrapper = Wrappers.query(mallLunbo).orderByAsc(new String[]{"sort_num"});
        Page<MallLunbo> page =  new Page<>(mallLunbo.getPageNum(), mallLunbo.getPageSize());
        return HttpResult.ok(mallLunboService.page(page, wrapper).getRecords());
    }

    /**
     *	根据objId获取轮播图具体信息
     * @Author wangbingcheng
     * @Date 2021年09月03日
     * @param objId
     * @Return
     */
    @GetMapping("lunbo_info_data")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('mall:lunbo:edit')")
    @Log(title = "商城管理>商城轮播图", businessType = BusinessType.UPDATE)
    public HttpResult<AdminLunboVO> lunboInfoData(@RequestParam Integer objId){
        return mallLunboService.lunboInfoData(objId);
    }

    /**
     *	获取轮播图展示位置下拉框数据
     * @Author wangbingcheng
     * @Date 2021年09月03日
     * @param
     * @Return
     */
    @GetMapping("locat_type_data")
    @ResponseBody
    public HttpResult<List<TencreatIdAndName>> locatTypeData(){
        return mallLunboService.locatTypeData();
    }


    @GetMapping("jump_info_data")
    @ResponseBody
    public HttpResult<List<TencreatIdAndName>> jumpInfoData(){
        List<TencreatIdAndName> jumpInfo = new ArrayList<TencreatIdAndName>();
//        jumpInfo.add(new TencreatIdAndName(JumpTypeEnum.MALL_SHOP.getType(),
//                TencreatMapData.lunboJumpType.get(JumpTypeEnum.MALL_SHOP.getType())));
        jumpInfo.add(new TencreatIdAndName(JumpTypeEnum.MALL_GOODS.getType(),
                TencreatMapData.lunboJumpType.get(JumpTypeEnum.MALL_GOODS.getType())));
        return HttpResult.ok(jumpInfo);
    }
    /**
     * 删除轮播图
     *
     * @author linjinzhan
     * @date 2018年11月14日
     * @param objId
     * @return
     */
    @ResponseBody
    @GetMapping("del")
    @PreAuthorize("@ss.hasPermi('mall:lunbo:remove')")
    @Log(title = "商城管理>商城轮播图", businessType = BusinessType.DELETE)
    public HttpResult<Boolean> del(@RequestParam Integer objId) {
        return mallLunboService.del(objId);
    }

    /**
     * 新增或修改轮播图
     *
     * @author linjinzhan
     * @date 2018年11月14日
     * @param adminLunboAddEditVo
     * @return
     */
    @ResponseBody
    @PostMapping("add_edit")
    @PreAuthorize("@ss.hasAnyPermi('mall:lunbo:add,mall:lunbo:edit')")
    @Log(title = "商城管理>商城轮播图", businessType = BusinessType.INSERT)
    public HttpResult<String> addEdit(@RequestBody AdminLunboAddEditDTO adminLunboAddEditVo) {
        return mallLunboService.addEdit(adminLunboAddEditVo);
    }

    /*****
     * 轮播图拖拽排序
     * @param file
     * @return
     */
    @ResponseBody
    @PostMapping("sort")
    public HttpResult<MallStorage> sort(@RequestBody ReqIdsParam ids) {
        return mallLunboService.sort(ids);
    }
}
